package com.zhulin.android.edoctor;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.http.client.methods.HttpPost;
import org.json.JSONException;
import org.json.JSONObject;

import com.zhulin.android.edoctor.jsonobject.INUserLogin;
import com.zhulin.android.edoctor.jsonobject.JOHospitalModel;
import com.zhulin.android.edoctor.net.AsyncHttpGet;
import com.zhulin.android.edoctor.net.AsyncHttpPost;
import com.zhulin.android.edoctor.net.DefaultThreadPool;
import com.zhulin.android.edoctor.net.RequestParameter;
import com.zhulin.android.edoctor.net.RequestResultCallback;
import com.zhulin.android.edoctor.net.exception.RequestException;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class TestActivity extends Activity{

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		Button btn=new Button(this);
		btn.setText("hk");
		btn.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				testHttpGet();
			}
		});
		
		this.setContentView(btn);
		
	}
	
	private void testHttpGet(){
		
		JSONObject jsonObject=new JSONObject();
		try {
			jsonObject.put("result", 1);
			jsonObject.put("name", "name");
		} catch (JSONException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		String s=jsonObject.toString();
		
		List<RequestParameter> parameterList = new ArrayList<RequestParameter>();
		parameterList.add(new RequestParameter("LoginName","tester-1"));
		parameterList.add(new RequestParameter("Password","123456"));
		
		//hashMap.put("LoginName", "tester-1");
		//hashMap.put("Password", "123456");
		
		INUserLogin inUserLogin=new INUserLogin();
		inUserLogin.setLoginName("tester-1");
		inUserLogin.setPassword("123456");
		
		Map<String, String> hashMap=inUserLogin.getClassInfo();
		
		AsyncHttpPost httpget = new AsyncHttpPost(null,"http://demo.jsqs.com.cn/Api/Api.aspx?action=UserLogin",hashMap,
				new RequestResultCallback(){

					@Override
					public void onSuccess(Object o) {
						Log.i("HttpGetExample", "HttpGetExample  request  onSuccess result :"+o);
					}
					
					@Override
					public void onFail(Exception e) {
						Log.i("HttpGetExample", "HttpGetExample  request   onFail :"+((RequestException)e).getMessage());
					}
		});
		
		DefaultThreadPool.getInstance().execute(httpget);
		
	}
}
